home *** CD-ROM | disk | FTP | other *** search
/ Aminet 31 / Aminet 31 (1999)(Schatztruhe)[!][Jun 1999].iso / Aminet / dev / gui / gtlayout.lha / Source / LTP_LayoutGadgets.c < prev    next >
C/C++ Source or Header  |  1998-09-09  |  30KB  |  1,126 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1998 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14. #include "Assert.h"
  15.  
  16. #ifdef DO_BOOPSI_KIND    /* Support code */
  17.  
  18. /*****************************************************************************/
  19.  
  20. #include <dos/dosextens.h>
  21.  
  22. /*****************************************************************************/
  23.  
  24. STATIC VOID
  25. LocalAddPart(STRPTR Base,STRPTR Name)
  26. {
  27.     LONG Len = strlen(Base);
  28.  
  29.     if(Base[Len - 1] != ':')
  30.         strcat(Base,"/");
  31.  
  32.     strcat(Base,Name);
  33. }
  34.  
  35. STATIC struct Library *
  36. OpenClass(STRPTR Name)
  37. {
  38.     struct Library *Result;
  39.  
  40.     Result = OpenLibrary(Name,0);
  41.     if(Result == NULL)
  42.     {
  43.         struct Process *    Process = (struct Process *)FindTask(NULL);
  44.         UBYTE                LocalBuffer[256];
  45.         LONG                i,Len;
  46.  
  47.         Len = strlen(Name);
  48.  
  49.         for(i = Len - 1 ; i >= 0 ; i--)
  50.         {
  51.             if(Name[i] == '/' || Name[i] == ':')
  52.             {
  53.                 Name = &Name[i + 1];
  54.  
  55.                 break;
  56.             }
  57.         }
  58.  
  59.         if(Process->pr_Task.tc_Node.ln_Type == NT_PROCESS && Process->pr_HomeDir != NULL)
  60.         {
  61.             strcpy(LocalBuffer,"PROGDIR:Classes/Gadgets");
  62.             LocalAddPart(LocalBuffer,Name);
  63.  
  64.             Result = OpenLibrary(LocalBuffer,0);
  65.         }
  66.  
  67.         if(!Result)
  68.         {
  69.             strcpy(LocalBuffer,":Classes/Gadgets");
  70.             LocalAddPart(LocalBuffer,Name);
  71.  
  72.             if(!(Result = OpenLibrary(LocalBuffer,0)))
  73.             {
  74.                 strcpy(LocalBuffer,"Gadgets");
  75.                 LocalAddPart(LocalBuffer,Name);
  76.  
  77.                 if(!(Result = OpenLibrary(LocalBuffer,0)))
  78.                     Result = OpenLibrary(Name,0);
  79.             }
  80.         }
  81.     }
  82.  
  83.     return(Result);
  84. }
  85.  
  86. #endif    /* DO_BOOPSI_KIND */
  87.  
  88.  
  89. /*****************************************************************************/
  90.  
  91.  
  92. VOID
  93. LTP_LayoutGadgets(LayoutHandle *Handle,ObjectNode *Group,LONG Left,LONG Top,LONG PlusWidth,LONG PlusHeight)
  94. {
  95.     if(!Handle->Failed)
  96.     {
  97.         STATIC const struct TagItem NoUnderscoreVanillaTags[] =
  98.         {
  99.             {TAG_DONE}
  100.         };
  101.  
  102.         STATIC const struct TagItem VanillaTags[] =
  103.         {
  104.             {GT_Underscore, '_'},
  105.             {TAG_DONE}
  106.         };
  107.  
  108.         STATIC const struct TagItem DisabledTags[] =
  109.         {
  110.             {GT_Underscore, '_' },
  111.             {GA_Disabled,    TRUE},
  112.             {TAG_DONE}
  113.         };
  114.  
  115.         STATIC const struct TagItem NoUnderscoreDisabledTags[] =
  116.         {
  117.             {GA_Disabled,    TRUE},
  118.             {TAG_DONE}
  119.         };
  120.  
  121.         struct NewGadget    NewGadget;
  122.  
  123.         struct Gadget *        Gadget;
  124.         struct Gadget *        Extra;
  125.         struct TagItem *    Tags;
  126.         ULONG                page;
  127.         ObjectNode *        Node;
  128.  
  129.         if(!Handle->List)
  130.         {
  131.             if(!(Handle->Previous = CreateContext(&Handle->List)))
  132.             {
  133.                 Handle->Failed = TRUE;
  134.  
  135.                 return;
  136.             }
  137.         }
  138.  
  139.         NewGadget.ng_TextAttr   = Handle->TextAttr;
  140.         NewGadget.ng_VisualInfo = Handle->VisualInfo;
  141.  
  142.         Group->Special.Group.Visible = TRUE;
  143.  
  144.         SCANPAGE(Group,Node,page)
  145.         {
  146.             if(Node->Type != FRAME_KIND && Node->Type != IMAGE_KIND && Node->Type != BLANK_KIND && Node->Type != BOX_KIND && Node->Type != XBAR_KIND && Node->Type != YBAR_KIND)
  147.             {
  148.                 Extra = NULL;
  149.  
  150.                 if(Node->GroupIndent)
  151.                 {
  152.                     NewGadget.ng_LeftEdge     = Node->Left + 4;
  153.                     NewGadget.ng_TopEdge    = Node->Top + 2;
  154.                     NewGadget.ng_Width        = Node->Width - (4 + 4);
  155.                     NewGadget.ng_Height        = Node->Height - (2 + 2);
  156.                 }
  157.                 else
  158.                 {
  159.                     NewGadget.ng_LeftEdge     = Node->Left;
  160.                     NewGadget.ng_TopEdge    = Node->Top;
  161.                     NewGadget.ng_Width        = Node->Width;
  162.                     NewGadget.ng_Height        = Node->Height;
  163.                 }
  164.  
  165.                 NewGadget.ng_GadgetText    = Node->Label ? Node->Label : (STRPTR)"";
  166.                 NewGadget.ng_GadgetID     = Node->ID;
  167.                 NewGadget.ng_UserData     = Node;
  168.  
  169.                 if(Node->NoKey)
  170.                 {
  171.                     if(Node->Disabled)
  172.                     {
  173.                         if(!V39 && (Node->Type == MX_KIND || Node->Type == LISTVIEW_KIND))
  174.                             Tags = (struct TagItem *)NoUnderscoreVanillaTags;
  175.                         else
  176.                             Tags = (struct TagItem *)NoUnderscoreDisabledTags;
  177.                     }
  178.                     else
  179.                         Tags = (struct TagItem *)NoUnderscoreVanillaTags;
  180.                 }
  181.                 else
  182.                 {
  183.                     if(Node->Disabled)
  184.                     {
  185.                         if(!V39 && (Node->Type == MX_KIND || Node->Type == LISTVIEW_KIND))
  186.                             Tags = (struct TagItem *)VanillaTags;
  187.                         else
  188.                             Tags = (struct TagItem *)DisabledTags;
  189.                     }
  190.                     else
  191.                         Tags = (struct TagItem *)VanillaTags;
  192.                 }
  193.  
  194.                 switch(Node->LabelPlace)
  195.                 {
  196.                     case PLACE_LEFT:
  197.  
  198.                         NewGadget.ng_Flags = PLACETEXT_LEFT;
  199.                         break;
  200.  
  201.                     case PLACE_RIGHT:
  202.  
  203.                         NewGadget.ng_Flags = PLACETEXT_RIGHT;
  204.                         break;
  205.  
  206.                     case PLACE_ABOVE:
  207.  
  208.                         NewGadget.ng_Flags = PLACETEXT_ABOVE;
  209.                         break;
  210.  
  211.                     case PLACE_BELOW:
  212.  
  213.                         NewGadget.ng_Flags = PLACETEXT_BELOW;
  214.                         break;
  215.  
  216.                     case PLACE_IN:
  217.  
  218.                         NewGadget.ng_Flags = PLACETEXT_IN;
  219.                         break;
  220.  
  221.                     default:
  222.  
  223.                         NewGadget.ng_Flags = NULL;
  224.                         break;
  225.                 }
  226.  
  227.                 if(Node->HighLabel)
  228.                     NewGadget.ng_Flags |= NG_HIGHLABEL;
  229.  
  230.                 Gadget = NULL; /* Always initialize this before entering the switch table. */
  231.  
  232.                 switch(Node->Type)
  233.                 {
  234.                     #ifdef DO_BOOPSI_KIND
  235.                     {
  236.                         case BOOPSI_KIND:
  237.                         {
  238.                             struct Gadget *Link;
  239.  
  240.                             if(Node->Special.BOOPSI.Link != NIL_LINK && Node->Special.BOOPSI.TagLink)
  241.                             {
  242.                                 if(!(Link = LTP_FindGadgetLinear(Handle,Node->Special.BOOPSI.Link)))
  243.                                 {
  244.                                     Handle->Failed = TRUE;
  245.  
  246.                                     return;    /* Note: must return since we are in a loop that
  247.                                              *       creates all gadgets for the current page.
  248.                                              */
  249.                                 }
  250.                             }
  251.                             else
  252.                                 Link = NULL;
  253.  
  254.                             if(Node->Special.BOOPSI.ClassLibraryName)
  255.                             {
  256.                                 if(!(Node->Special.BOOPSI.ClassBase = OpenClass(Node->Special.BOOPSI.ClassLibraryName)))
  257.                                 {
  258.                                     break;
  259.                                 }
  260.                             }
  261.  
  262.                             if(Node->Special.BOOPSI.FullWidth)
  263.                             {
  264.                                 NewGadget.ng_LeftEdge    = Node->Special.BOOPSI.Parent->Left;
  265.                                 NewGadget.ng_Width        = Node->Special.BOOPSI.Parent->Width;
  266.                             }
  267.  
  268.                             if(Node->Special.BOOPSI.FullHeight)
  269.                             {
  270.                                 NewGadget.ng_TopEdge    = Node->Special.BOOPSI.Parent->Top;
  271.                                 NewGadget.ng_Height        = Node->Special.BOOPSI.Parent->Height;
  272.                             }
  273.  
  274.                             Gadget = NewObject(Node->Special.BOOPSI.ClassInstance,Node->Special.BOOPSI.ClassName,
  275.                                 GA_Left,        NewGadget.ng_LeftEdge,
  276.                                 GA_Top,            NewGadget.ng_TopEdge,
  277.                                 GA_Width,        NewGadget.ng_Width,
  278.                                 GA_Height,        NewGadget.ng_Height,
  279.                                 GA_Disabled,    Node->Disabled,
  280.                                 GA_ID,            Node->ID,
  281.                                 GA_UserData,    Node,
  282.  
  283.                                 Link ? Node->Special.BOOPSI.TagLink : TAG_IGNORE,                                    Link,
  284.                                 Handle->BOOPSIPrevious ? GA_Previous : TAG_IGNORE,                                    Handle->BOOPSIPrevious,
  285.                                 Node->Special.BOOPSI.TagTextAttr ? Node->Special.BOOPSI.TagTextAttr : TAG_IGNORE,    Handle->TextAttr,
  286.                                 Node->Special.BOOPSI.TagDrawInfo ? Node->Special.BOOPSI.TagDrawInfo : TAG_IGNORE,    Handle->DrawInfo,
  287.                                 Node->Special.BOOPSI.TagScreen ? Node->Special.BOOPSI.TagScreen : TAG_IGNORE,        Handle->Screen,
  288.                                 Node->Special.BOOPSI.ClassTags ? TAG_MORE : TAG_DONE,                                Node->Special.BOOPSI.ClassTags);
  289.  
  290.                             break;
  291.                         }
  292.                     }
  293.                     #endif /* DO_BOOPSI_KIND */
  294.  
  295.                     #ifdef DO_POPUP_KIND
  296.                     {
  297.                         case POPUP_KIND:
  298.  
  299.                             Gadget = NewObject(LTP_PopupClass,NULL,
  300.                                 GA_Left,            NewGadget.ng_LeftEdge,
  301.                                 GA_Top,                NewGadget.ng_TopEdge,
  302.                                 GA_Width,            NewGadget.ng_Width,
  303.                                 GA_Height,            NewGadget.ng_Height,
  304.                                 GA_Disabled,        Node->Disabled,
  305.                                 GA_ID,                Node->ID,
  306.                                 GA_UserData,        Node,
  307.                                 GA_RelVerify,        TRUE,
  308.                                 PIA_Labels,            Node->Special.Popup.Choices,
  309.                                 PIA_Active,            Node->Current,
  310.                                 PIA_Font,            Handle->TextAttr,
  311.                                 PIA_CentreActive,    Node->Special.Popup.CentreActive,
  312.                                 PIA_AspectX,        Handle->AspectX,
  313.                                 PIA_AspectY,        Handle->AspectY,
  314.  
  315.                                 Handle->BOOPSIPrevious ? GA_Previous : TAG_IGNORE,Handle->BOOPSIPrevious,
  316.                             TAG_DONE);
  317.  
  318.                             break;
  319.                     }
  320.                     #endif /* DO_POPUP_KIND */
  321.  
  322.                     #ifdef DO_TAB_KIND
  323.                     {
  324.                         case TAB_KIND:
  325.  
  326.                             if(Node->Special.Tab.FullWidth)
  327.                             {
  328.                                 NewGadget.ng_LeftEdge    = Handle->TopGroup->Left    - Left;
  329.                                 NewGadget.ng_Width        = Handle->TopGroup->Width    + PlusWidth;
  330.  
  331.                                 NewGadget.ng_LeftEdge    += Handle->Screen->WBorLeft;
  332.                                 NewGadget.ng_Width        -= Handle->Screen->WBorLeft + Handle->Screen->WBorRight;
  333.                             }
  334.                             else
  335.                             {
  336.                                 NewGadget.ng_LeftEdge    = Node->Special.Tab.Parent->Left;
  337.                                 NewGadget.ng_Width        = Node->Special.Tab.Parent->Width;
  338.                             }
  339.  
  340.                             Gadget = NewObject(LTP_TabClass,NULL,
  341.